<script>
    var divString = '<div id="container" style="width: 400px;height:400px;display:inline-block"></div>'
    layui.$(".layui-body").html(divString)
    var container = document.getElementById('container');
    // 初始化echarts对象
    var myContainer = echarts.init(container);

    let date = [10, 9, 8, 7, 6, 5 ,4 ,3, 2, 1];
    //设置图标配置项
    myContainer.setOption({
        title:{
            text:'需求应答时间'
        },
        xAxis:{
            type:"category",
            boundaryGap:false,
            data:date
        },
        yAxis:{
            boundaryGap:[0,'100%'],
            type:'value'
        },
        series:[{
            name:'成交',
            type:'line',
            smooth:true, //数据光滑过度
            symbol:'none', //下一个数据点
            stack:'a',
            areaStyle:{
                normal:{
                    color:'pink'
                }
            },
            data:[]
        }]
    })

    function refresh_data() {
        layui.$.ajax({
            type : "get",
            async : false,  //同步请求
            url : "http://localhost:8080/statistics/answer_time",
            success:function(data){
                refresh_figure(data);
            },
            error: function() {
                //layui 弹出层
            }
        })
    }

    function refresh_figure(data) {
        var performance_data = JSON.parse(data);
        myContainer.setOption({
            xAxis:{
                data:date
            },
            series:[{
                name : '需求应答时间',
                data : performance_data['answer_times']
            }]
        });
    }

    refresh_data()

    var timerId = setInterval(function(){
        refresh_data()
    }, 5000)

    timerIds.push(timerId)
</script>